/**
 * 
 */
package com.gr.staffpm.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author Graham Rhodes 7 Apr 2011 18:27:45
 */
public class ByteArrayStreamResourceWriter extends AbstractResourceStreamWriter {

    private static final long serialVersionUID = 1L;
    private final Logger log = LoggerFactory.getLogger(ByteArrayStreamResourceWriter.class);
    private final ByteArrayOutputStream out;
    private final String contentType;

    public ByteArrayStreamResourceWriter(ByteArrayOutputStream out, String contentType) {
        super();
        this.out = out;
        this.contentType = contentType;
    }

    /* (non-Javadoc)
     * @see org.apache.wicket.util.resource.IResourceStreamWriter#write(java.io.OutputStream)
     */
    @Override
    public void write(OutputStream output) {
        try {
            out.writeTo(output);
        } catch (IOException e) {
            log.error("Exception writing excel file.");
        }
    }

    /* (non-Javadoc)
     * @see org.apache.wicket.util.resource.IResourceStream#getContentType()
     */
    @Override
    public String getContentType() {
        return contentType;
    }

}
